package com.zjitc.service.impl;

import com.zjitc.dao.OrderDao;
import com.zjitc.dao.ProductDao;
import com.zjitc.model.Order;
import com.zjitc.model.OrderItem;
import com.zjitc.model.Product;
import com.zjitc.service.OrderService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/24 14:38
 * @description:
 */
@Service
public class OrderServiceImpl implements OrderService {

  @Autowired
  private OrderDao orderDao;

  @Autowired
  private ProductDao productDao;

  @Override
  public void orderPayment(String oid, String name, String phone, String address) {
    orderDao.orderPayment(oid,name,phone,address);
  }

  @Override
  public void createOrderItem(OrderItem orderItem) {
    orderDao.createOrderItem(orderItem);
  }

  @Override
  public void createOrder(Order order) {
    orderDao.createOrder(order);
  }

  @Override
  public List<Order> findOrder(Integer uid) {
    List<Order> orderList = orderDao.findOrder(uid);
    for (Order item : orderList){
      List<OrderItem> orderItem = orderDao.findOrderItems(item.getOid());
      for (OrderItem item1 : orderItem){
        Product product = productDao.showProduct(item1.getPid());
        item1.setProduct(product);
      }
      item.setOrderItemList(orderItem);
    }
    return orderList;
  }

  @Override
  public void deleteOrder(String oid) {
    orderDao.deleteOrder(oid);
  }

  @Override
  public void updateState(String oid) {
    orderDao.updateState(oid);
  }

}
